export default {
	//金额/100，保留两位小数，type == arr  返回数组
	ismoney(val, num = 2, type) {
		let price = '0.00';
		if (typeof val === "number") {
			price = (val / 100).toFixed(num);
		}
		return type && type == 'arr' ? price.split('.') : price;
	},
	//格式化图片
	imgFormat(url, type) {
		if (type) return url
		if (url) {
			if (url.indexOf("http") < 0) {
				return import.meta.env.VITE_OSS + url;
			} else {
				return url;
			}
		}
	},
	// 头像
	avatar(url) {
		return this.imgFormat(url ? url : '/profile/picture/2025/06/05/5240fa69-9003-4391-9765-6bbdbbbcd00d.png')
	},
	//电话号码隐藏中间四位
	maskPhoneNumber(phoneNumber) {
		return String(phoneNumber).replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
	},
	isPhone(phoneNumber) {
		return /^1[3-9]\d{9}$/.test(phoneNumber);
	},
	//邮箱格式验证
	isEmail(email) {
		return /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(email);
	},
	//复制文本
	copyText(data) {
		uni.setClipboardData({
			data,
			success: () => {
				uni.showToast({
					title: "复制成功",
					icon: 'success',
					duration: 2000
				})
			}
		})
	},

}